package com.crm.controller;


import com.crm.base.PageResult;
import com.crm.base.ResponseResult;
import com.crm.domain.dto.ClueDto;
import com.crm.domain.entity.Clue;
import com.crm.domain.vo.ClueVo;
import com.crm.service.ClueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "线索管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/clues")
public class ClueController {
    private final ClueService clueService;

    /**
     * 分页查询线索信息
     * @param
     * @return
     */
    @ApiOperation(value = "分页查询线索信息")
    @GetMapping("/clue/list")
    public PageResult<List<ClueVo>> page(ClueDto clueDto) {
        PageResult<ClueVo> pageResult = clueService.queryAll(clueDto);
        return PageResult.success(pageResult.getMsg(), pageResult.getRows(), pageResult.getTotal());
    }

    /**
     * 添加线索信息
     * @param clue
     * @return
     */
    @ApiOperation(value = "添加线索信息")
    @PostMapping("/clue")
    public ResponseResult insertInfo(@RequestBody Clue clue){
        clueService.save(clue);
        return ResponseResult.success("添加成功");
    }

    /**
     * 根据id查询线索信息
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询线索信息")
    @GetMapping("/clue/{id}")
    public ResponseResult<ClueVo> getById(@PathVariable("id") Long id) {
        Clue clue = clueService.getById(id);
        return ResponseResult.success(clue);
    }

    @ApiOperation(value = "查询线索信息")
    @GetMapping("/record/list")
    public ResponseResult<ClueVo> getClue(Long clueId){
        Clue clue = clueService.getById(clueId);
        return ResponseResult.success(clue);
    }

    /**
     * 线索池分页查询
     * @param clueDto
     * @return
     */
    @ApiOperation(value = "线索池分页查询")
    @GetMapping("/clue/pool")
    public PageResult<List<ClueVo>> cluePool(ClueDto clueDto) {
        PageResult<ClueVo> pageResult = clueService.queryPool(clueDto);
        return PageResult.success(pageResult.getMsg(),pageResult.getRows(),pageResult.getTotal());
    }

    /**
     * 线索池保存修改
     * @param clue
     * @return
     */
    @ApiOperation(value = "线索保存修改")
    @PostMapping("/record")
    public ResponseResult updateClue(Clue clue){
        clue.setId(152L);
        clue.setClueId(123L);
        clueService.addInfo(clue);
        return ResponseResult.success();
    }


    /**
     * 转为伪线索
     * @param
     * @return
     */
    @ApiOperation(value = "转为伪线索")
    @PutMapping("/clue/false/{id}")
    public ResponseResult setFalseClue(@PathVariable("id") Long clueId,@RequestBody ClueDto clueDto) {
        clueService.setFalseClue(clueId,clueDto);
        return ResponseResult.success();
    }
}